<?php
    Class User_revenue_model extends CI_Model
    {
        public function __construct()
        {
          parent::__construct();
        }       

       public function index()
       {

       }

       public function calcRevenue($product_id = false, $user_id = false, $size = false,$product_code = false)
       {
          $this->db->select('*');
          $this->db->from('user_revenue');

          if(!empty($product_id))          
            $this->db->where('product_id', $product_id);
          if(!empty($user_id))          
            $this->db->where('user_id', $user_id);
          if(!empty($size))          
            $this->db->where('size', $size);
          if(!empty($product_code))          
            $this->db->where('product_code', $product_code);

          $query = $this->db->get();

          return $query->row();
       }

       public function search($cond = false)
       {
        $this->db->select('*');
        $this->db->from('user_revenue');

        if(!empty($cond['product_id']) || !empty($cond['user_id']))
        {
          if(!empty($cond['product_id']))
            $this->db->where('product_id', $cond['product_id']);
          if(!empty($cond['user_id']))
            $this->db->where('user_id', $cond['user_id']);

          $query = $this->db->get();
          return $query->row();
        }

        if(!empty($cond['user_id1']))
        {
          $this->db->where('user_id', $cond['user_id1']);
          $query = $this->db->get();
          return $query->result();
        }

        $query = $this->db->get();
        return $query->result();
       }

       public function update($data,$user_revenue_id)
       {
          $this->db->where('id', $user_revenue_id);

          return $this->db->update('user_revenue', $data);
       }

       public function insert($data)
       {
        return $this->db->insert('user_revenue', $data);
       }
    }
?>
